package org.zfes.snowier.cloud.zbss.metting.router.service.pub;

import java.util.List;
import java.util.Map;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.zfes.snowier.auth.shiro.util.SecurityUtil;
import org.zfes.snowier.cloud.zbss.metting.biz.dto.SignupInfoDto;
import org.zfes.snowier.cloud.zbss.metting.biz.dto.SignupModelJsonDto;
import org.zfes.snowier.cloud.zbss.metting.biz.model.SignupModel;
import org.zfes.snowier.cloud.zbss.metting.biz.service.ISignupModelService;
import org.zfes.snowier.cloud.zbss.metting.biz.service.ISignupService;
import org.zfes.snowier.common.file.FileResInfo;
import org.zfes.snowier.common.file.disk.UploadUitl;
import org.zfes.snowier.core.data.DataSet;
import org.zfes.snowier.core.util.ZAlert;
import org.zfes.snowier.web.controller.BaseController;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.beust.jcommander.internal.Maps;
@Controller("org.zfes.snowier.cloud.zbss.metting.router.service.pub.SignupDefineController")  
@RequestMapping("/met/service/pub/signupDefine")
public class SignupDefineController extends BaseController {

	@Autowired
	private ISignupModelService signupModelService;
	@Autowired
	private ISignupService signupService;


	@RequestMapping(value="/loadSignupModel", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public @ResponseBody  Object loadSignupModel(Long metId){
		Optional<SignupModel> signupModel =  signupModelService.loadSignupModelByMetId(metId);
		return ajaxQuery("signupModel", signupModel);
	}
	@RequestMapping(value="/submitSignup", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public @ResponseBody  Object submitSignup(Long metId,@RequestParam Map<String,Object> params){
		System.out.println(metId);
		System.out.println(params);
		signupService.createSignup(metId, params);
		return ajaxDoneSuccess("数据操作成功 ");
	}
	@RequestMapping(value="/showSignup", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public @ResponseBody  Object submitSignup(Long metId,Long signupId){
		List<SignupInfoDto> signupInfoDtoList=signupService.loadSignup( metId, signupId);
		return ajaxQuery("signupInfos", signupInfoDtoList);
	}
    @RequestMapping(value = "/uploadAttaches", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody Object uploadImage(@RequestParam(name = "qqfile", required = false) MultipartFile file) {
    	FileResInfo   resInfo =null;
    	try {
    		String fileName=file.getOriginalFilename();
    		if(fileName!=null&&fileName.contains(",")) {
    			ZAlert.newSLE("文件名不能包含符号（,）");
    		}
        	 resInfo = UploadUitl.tranferFile(file, "signupattaches");
        	Map<String,Object> res=  Maps.newHashMap();
        	res.put("success", true);
        	res.put("url", resInfo.getFilePath());
        	  return res;
        	 //return ajaxQuery("attach", resInfo);
        } catch (Exception e) {
//            ZAlert.appRuntimeError(e.getMessage());
        	Map<String,Object> res=  Maps.newHashMap();
            res.put("success", false);
        	//res.put("url", resInfo.getFilePath());
        	return res;
        }
       // return ajaxQuery("attach", resInfo);
    }
	
   

}